package com.boot.producer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/**
 * DESC: kafak生产者
 *
 * @author WangJie
 * @date Created in 2025-03-04 20:19
 */

@Component
public class KafkaProducer {
    private static final Logger logger = LoggerFactory.getLogger(KafkaProducer.class);

    private static final String TOPIC = "topic-test";

    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    public void sendMessage(String message) {
        logger.info("Sending message:'{}' to topic:'{}'", message, TOPIC);
        kafkaTemplate.send(TOPIC, message);
    }
}
